import React from 'react'
import {connect} from 'dva'
import {Input, Button} from "antd";
import user from "../../mock/user";

@connect(({createTopic}) => ({
  createTopic
}))

export default class CreateTopic extends React.Component {
  onChange(type, value) {
    let payload = {};
    payload[type] = value.target.value;
    this.props.dispatch({
      type: 'createTopic/overrideStateProps',
      payload
    })
  }

  create() {
    this.props.dispatch({
      type: 'createTopic/create',
    })
  }

  render() {
    const {createTopic} = this.props;
    // eslint-disable-next-line no-shadow
    const {title, content, user} = createTopic;
    return (
      <div>
        title <Input onChange={this.onChange.bind(this, 'title')}
                     value={title}/>

        user <Input onChange={this.onChange.bind(this, 'user')}
                    value={user}/>
        content <Input.TextArea onChange={this.onChange.bind(this, 'body')}
                                value={content}/>
        <Button onClick={this.create.bind(this)}>submit</Button>
      </div>
    )
  }
}


